package com.shawn.server.interceptor;

import com.shawn.model.entity.User;

public class ThreadContext {
    /**
     * 线程变量副本数据
     */
    private static final ThreadLocal<User> threadLocal = new ThreadLocal<>();

   public static void setUser(User user){
       threadLocal.set(user);
   }

   public static User getUser(){
       return threadLocal.get();
   }

   public static Long getUserId(){
        if (threadLocal.get()!=null){
            return threadLocal.get().getId();
        }
        return null;
   }
   public static String getUserPhone(){
       if (threadLocal.get()!=null){
           return threadLocal.get().getMobile();
       }
       return null;
   }
   public static void clear(){
       threadLocal.remove();
   }

}
